// This is JDefenceTower, a simple tower defence style game
//
// Copyright (C) 2010 Maximilian Junker
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 3 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, see <http://www.gnu.org/licenses/>.

package junker.defence.ui;

import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JFrame;

import junker.defence.model.CreationPattern;
import junker.defence.model.Game;
import junker.defence.model.MapObjectDescription;
import junker.defence.model.Player;

@SuppressWarnings("serial")
public class PlayerUI extends JFrame{

	private Player player;
	private MapUI mapUi;
	
	public PlayerUI(final Player player) {
		super();
		this.player = player;
		this.mapUi = new MapUI(player.getMap());
		this.getContentPane().setLayout(new BorderLayout());
		this.getContentPane().add(mapUi, BorderLayout.CENTER);

		mapUi.addMouseListener(new MouseAdapter(){
			@Override
			public void mousePressed(MouseEvent e) {
				// TODO Auto-generated method stub
				Point p = e.getPoint();
				MapObjectDescription d = new MapObjectDescription();
				if(e.getButton()==MouseEvent.BUTTON1){
					d.setBarrier(true);
				}
				else {
					d.setDoesCreate(true);
					MapObjectDescription d2 = new MapObjectDescription();
					d2.setMovesToSink(true);
					d2.setDoesCreate(false);
					d2.setSpeed(3);
					
					CreationPattern pattern = new CreationPattern(1000);
					pattern.set(0, d2);
					pattern.set(200, d2);
					pattern.set(500, d2);
					
					d.setCreationPattern(pattern);
					d.setDoesCreate(true);
				}
				player.createObject(d,(float)Math.floor(p.x / UIConfig.SCALE),(float)Math.floor(p.y/UIConfig.SCALE));
			}
		});
	}
	
	public void updateUI(){
		this.mapUi.draw();
	}

}
